﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using mirabyte.Mobile.TouchControls2;
using SartmenuEditor.Properties;

namespace SartmenuEditor.helper
{
    class Global
    {
        private static byte[] Resize(Image image, Size size)
        {
            Image bmp = new Bitmap(size.Width, size.Height);
            using (var g = Graphics.FromImage(bmp))
            {
                g.DrawImage(
                    image,
                    new Rectangle(0, 0, size.Width, size.Height),
                    new Rectangle(0, 0, image.Width, image.Height),
                    GraphicsUnit.Pixel);
            }
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, ImageFormat.Png);
            return ms.GetBuffer();
        }
        public static AlphaImage getAlphaImage(string resource)
        {
            return AlphaImage.FromEmbeddedResource(string.Format("StartmenuEditor.ImageResources.{0}", resource), Assembly.GetExecutingAssembly());
        }
        public static AlphaImage getAlphaImage(string resource, Size size)
        {
            Image img = (Image)ImageResources.ResourceManager.GetObject(
                resource,
                CultureInfo.CurrentUICulture);
            return AlphaImage.FromByteArray(Resize(img, size));
        }

        public static string getString(string name)
        {
            return Resources.ResourceManager.GetString(name, CultureInfo.CurrentUICulture).Replace(@"\n", Environment.NewLine);
        }
        public static void showMessageBox(string title, string text, string button1)
        {
            mirabyte.Mobile.TouchControls2.Dialogs.GlassDialog.ShowDialog(title, text, button1);
        }
        public static int showMessageBox(string title, string text, string button1, string button2)
        {
            return mirabyte.Mobile.TouchControls2.Dialogs.GlassDialog.ShowDialog(title, text, button1, button2);
        }
    }
}
